<?php

namespace Controller\Install;

use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;

class InstallCSP implements ControllerProviderInterface {
    public function connect(Application $app) {
        $controllers = $app ['controllers_factory'];
        $controllers->match ( '/', function (Application $app) {
            
            $data = array (
                            'name' => 'Your name',
                            'email' => 'Your email' 
            );
            
            $form = $app ['form.factory']->createBuilder ( 'form', $data )->add ( 'name' )->add ( 'email' )->add ( 'gender', 'choice', array (
                            'choices' => array (
                                            1 => 'male',
                                            2 => 'female' 
                            ),
                            'expanded' => true 
            ) )->getForm ();
            
            // $form->handleRequest ( $request );
            
            if ($form->isValid ()) {
                $data = $form->getData ();
                
                // do something with the data
                
                // redirect somewhere
                return $app->redirect ( '...' );
            }
            
            // Render
            return $app ['twig']->render ( "default.twig", array (
                            'form' => $form->createView () 
      ) );
    }, 'GET|POST' );
    
    return $controllers;
  }
}